/**
 * 
 */
package com.qf.apps;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.qf.apps.vo.UserForm;
import com.qf.domain.User;
import com.qf.service.UserService;

/**
 * @author 123
 * 
 */
public class AddUserController extends SimpleFormController {
	private UserService userService;

	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		System.out.println("formBackingObject");
		return new UserForm();
	}

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		UserForm userForm = (UserForm) command;
		User user = userForm.getUser();
		int id = this.userService.add(user);
		return new ModelAndView(this.getSuccessView());
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
}
